package com.cskaoyan.wordmemorize.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cskaoyan.wordmemorize.dao.entity.UserVocBoundLogDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserVocBoundLogMapper extends BaseMapper<UserVocBoundLogDO> {
    /**
     * 统计用户的单词上限日志总数
     */
    @Select("SELECT COUNT(*) FROM user_voc_bound_log WHERE user_id = #{userId} AND is_deleted = 0")
    Long countByUserId(@Param("userId") Long userId);

    /**
     * 分页查询用户的单词上限日志
     */
    @Select("SELECT id, user_id, type, log_date, count, description " +
            "FROM user_voc_bound_log " +
            "WHERE user_id = #{userId} AND is_deleted = 0 " +
            "ORDER BY log_date DESC, create_time DESC " +
            "LIMIT #{offset}, #{pageSize}")
    List<UserVocBoundLogDO> selectByUserId(
            @Param("userId") Long userId,
            @Param("offset") int offset,
            @Param("pageSize") int pageSize
    );
}
